/*
 * @Author: HeAo
 * @Date: 2021-11-03 15:04:31
 * @LastEditTime: 2021-11-03 16:03:06
 * @LastEditors: HeAo
 * @Description:
 * @FilePath: \web2103-2105\web2105\4-1-Nodejs\day04\app02\index.js
 * 别乱动！
 */
const express = require('express');
const app = express();
// 导入中间件
const cookieParser = require('cookie-parser');
const serveStatic = require('serve-static');
const cors = require('cors');

// 导入路由子模块
const userRouter = require('./routes/user')

// 使用中间件（在子路由模块注入之前使用）
app.use(cookieParser())
app.use(serveStatic('public'))
app.use(cors({
  "origin": "*",
  "methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
  "preflightContinue": false,
  "optionsSuccessStatus": 204
}))

// 将子路由模块注入到根app中
app.use('/user', userRouter)

app.get('/getCookie', (req, res) => {
  res.cookie('name', 'zhangsan');
  res.send('获取cookie成功')
})

app.listen(3000, () => {
  console.log('3000 server is running');
})
